<script lang="ts" setup>
const isShowBackTop = ref(false);
const backTop = () => {
  window.scrollTo({
    top: 0,
    behavior: "smooth",
  });
};
const handleScroll = () => {
  if (document.documentElement.scrollTop > 100) {
    isShowBackTop.value = true;
  } else {
    isShowBackTop.value = false;
  }
};
onMounted(() => {
  window.addEventListener("scroll", handleScroll);
});
onBeforeUnmount(() => {
  window.removeEventListener("scroll", handleScroll);
});
</script>

<template>
  <div v-if="isShowBackTop" class="backtop" @click="backTop">
    <svg
      viewBox="0 0 48 48"
      fill="none"
      stroke="currentColor"
      stroke-width="4"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="ele-arrow-up"
    >
      <path d="M10 31 24 17 38 31" />
    </svg>
  </div>
</template>

<style lang="scss" scoped>
.backtop {
  cursor: pointer;
  z-index: 8;
  position: fixed;
  right: 30px;
  bottom: 60px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 12px;
  color: #e22000;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s,background-color .2s;
  box-shadow: 0 6px 16px 0 rgba(0, 0, 0, .08), 0 3px 6px -4px rgba(0, 0, 0, .12), 0 9px 28px 8px rgba(0, 0, 0, .05);
  svg {
    width: 25px;
  }
}
</style>
